package com.snack.system.controller;

import com.snack.common.core.web.controller.BaseController;
import com.snack.common.core.web.domain.AjaxResult;
import com.snack.common.core.web.page.TableDataInfo;
import com.snack.common.log.annotation.Log;
import com.snack.common.log.enums.BusinessType;
import com.snack.common.security.annotation.RequiresPermissions;
import com.snack.system.domain.TsMsg;
import com.snack.system.service.ITsMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息Controller
 * 
 * @author snack
 * @date 2022-09-18
 */
@RestController
@RequestMapping("/msg")
public class TsMsgController extends BaseController
{
    @Autowired
    private ITsMsgService msgService;

    /**
     * 查询消息列表
     */
    @RequiresPermissions("system:msg:list")
    @GetMapping("/list")
    public TableDataInfo list(TsMsg msg)
    {
        startPage();
        List<TsMsg> list = msgService.selectList(msg);
        return getDataTable(list);
    }

    /**
     * 获取消息详细信息
     */
    @RequiresPermissions("system:msg:query")
    @GetMapping(value = "/{msgId}")
    public AjaxResult getInfo(@PathVariable("msgId") Long msgId)
    {
        return AjaxResult.success(msgService.selectById(msgId));
    }

    /**
     * 新增消息
     */
    @RequiresPermissions("system:msg:add")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TsMsg msg)
    {
        return toAjax(msgService.insert(msg));
    }

    /**
     * 修改消息
     */
    @RequiresPermissions("system:msg:edit")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TsMsg msg)
    {
        return toAjax(msgService.update(msg));
    }

    /**
     * 删除消息
     */
    @RequiresPermissions("system:msg:remove")
    @Log(title = "消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{msgIds}")
    public AjaxResult remove(@PathVariable Long[] msgIds)
    {
        return toAjax(msgService.deleteByIds(msgIds));
    }
}
